import {
	mapMutations
} from 'vuex'
// 引入antv组件
import F2 from '@/uni_modules/lime-f2/components/l-f2/f2-all.min.js';
export default {
	...mapMutations([
		'upUserInfo'
	]),
	toSend() {
		this.$refs.sendPopup.open()
	},
	//获取今日今指数图表数据
	getTodayIndex(id) {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getTodayIndex',
			params: {},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.baseData = res.data
					// 班组考勤==========================================================================
					this.$refs.todayIndex.init(config => {
						config.padding = ['auto', 20, 'auto', 'auto']
						const chart = new F2.Chart(config);
						chart.source(that.baseData, {
							// value:{//y轴的数值间隔
							// 	tickCount:30
							// }
						});
						chart
							.interval()
							.position('date*pointTotal')
							.color('date*pointTotal', ['rgba(252, 67, 142, 1)',
								'rgba(35, 193, 101, 1)', 'rgba(255, 150, 43, 1)',
								'rgba(92, 159, 254, 1)'
							])
							.style('pointTotal', {
								radius: function radius(val) {
									return val > 0 ? [2, 2, 0, 0] : [0, 0, 2, 2];
								}
							})
							.adjust('stack'); //不分组
						chart.axis('date', {
							label: {
								fill: '#666666',
								rotate: -Math.PI / 2,
								textAlign: 'end',
								textBaseline: 'middle'
							}
						});
						chart.legend(false);
						// 柱状图添加文本
						that.baseData.forEach(function(obj) {
							chart.guide().text({
								position: [obj.date, obj.pointTotal],
								content: obj.pointTotal,
								style: {
									textAlign: 'center',
									textBaseline: 'bottom'
								},
								offsetY: 0
							});
						});
						chart.render();
						// 需要把 chart 返回
						return chart;
					})

				} else {
					// console.log("失败")
					that.$httpRequest.get({
						that: that,
						url: 'h5/getSiteIndex',
						params: {},
						success: res => {
							if (res.code === that.$httpConfig.SUCCESS_CODE) {
								that.baseData = res.data
								// 班组考勤==========================================================================
								this.$refs.todayIndex.init(config => {
									config.padding = ['auto', 20, 'auto', 'auto']
									const chart = new F2.Chart(config);
									chart.source(that.baseData, {
										// value:{//y轴的数值间隔
										// 	tickCount:30
										// }
									});
									chart
										.interval()
										.position('date*pointTotal')
										.color('date*pointTotal', [
											'rgba(252, 67, 142, 1)',
											'rgba(35, 193, 101, 1)',
											'rgba(255, 150, 43, 1)',
											'rgba(92, 159, 254, 1)'
										])
										.style('pointTotal', {
											radius: function radius(val) {
												return val > 0 ? [2, 2, 0, 0] :
													[0, 0, 2, 2];
											}
										})
										.adjust('stack'); //不分组
									chart.axis('date', {
										label: {
											fill: '#666666',
											rotate: -Math.PI / 2,
											textAlign: 'end',
											textBaseline: 'middle'
										}
									});
									chart.legend(false);
									// 柱状图添加文本
									that.baseData.forEach(function(obj) {
										chart.guide().text({
											position: [obj.date, obj
												.pointTotal
											],
											content: obj.pointTotal,
											style: {
												textAlign: 'center',
												textBaseline: 'bottom'
											},
											offsetY: 0
										});
									});
									chart.render();
									// 需要把 chart 返回
									return chart;
								})
							}

						}
					})
				}

			}
		})
	},
	handlerUpload() {
		let that = this;
		//上传照片
		that.$httpRequest.handlerUploadPic(res => {
			if (res.code === that.$httpConfig.SUCCESS_CODE) {
				// console.log(res,"完成上传")
				that.wordList.push(res.data)
				var newlist = that.wordList.map((item, index) => {
					return item = item.id
				})
				that.formData.picture = newlist.join(',')

			}
		});
	},
	toMyTodayData() {
		uni.navigateTo({
			url: '/pages/index/myTodayData'
		})
	},
	//删除照片
	del(index) {
		this.wordList.splice(index, 1)
		var newlist = this.wordList.map((item, index) => {
			return item = item.id
		})
		this.formData.picture = newlist.join(',')
	},
	_previewImage(image) {
		var imgArr = [];
		imgArr.push(image);
		//预览图片
		uni.previewImage({
			urls: imgArr,
			current: imgArr[0]
		});
	},
	closeSendPopup() {
		this.$refs.sendPopup.close()
	},
	//发表想法
	submit() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'h5/publishThought',
			params: that.formData,
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.$toast.msg('发布成功', {
						icon: 1
					})
					that.closeSendPopup()
				} else {
					that.$toast.msg(res.message, {
						icon: 1
					})
				}

			}
		})
	},
	//获取今日标签记录列表
	getTodayRecordList() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getTodayRecordList',
			params: {
				pageNo: that.page,
				pageSize: that.list_rows,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.recordList = res.data.rows
					} else {
						that.recordList = that.recordList.concat(res.data.rows)
					}
					that.page++
				} else {

				}
			}
		})

	},
	//获取我的全部前置导航
	getMyAllLinks() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getMyAllLinks',
			params: {},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.topLinkList = res.data
				} else {

				}
			}
		})

	},
	//获取全部导航链接
	getAllLinks() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getAllLinks',
			params: {},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.linkList = res.data
				} else {

				}
			}
		})

	},
	tagLongTap(id, name, isAdd) {
		this.currenLinkName = name;
		this.currenLinkId = id;
		this.currenLinkIsTop = isAdd;
		this.$refs.confirmPopup2.open();
	},
	tagUrlClick(link) {
		window.location.href = link
	},
	close() {
		this.$refs.confirmPopup.close();
		this.$refs.confirmPopup2.close();
	},
	sumbitLinkTop() {
		let that = this
		let url = this.currenLinkIsTop ? url = "h5/removeUserLink" : url = "h5/addUserLink"
		that.$httpRequest.request({
			that: that,
			url: url,
			params: {
				linkId: that.currenLinkId
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.getMyAllLinks()
					that.getAllLinks()

				} else {

				}
			}
		})
		this.$refs.confirmPopup2.close();

	},







	//切换分类
	selectTab(index, color, id, name) {
		this.current = index
		this.currentColor = color
		this.current_typeName = name
		this.getAllTag(id)
	},
	toSearch() {
		uni.navigateTo({
			url: '/pages/index/search'
		})
		// this.$toast.msg("暂未开放！", {
		// 	icon: 1
		// })
	},
	toNotice() {
		uni.navigateTo({
			url: '/pages/my/notice'
		})
	},
	//标签点击记录
	tagClick(id, index, points) {
		let that = this
		if (!this.userInfo.nickname) {
			that.showNumber = true
			setTimeout(() => {
				that.showNumber = false
			}, 2000)
			that.topicList[index].clicked = true
		}
		that.currentNumber = points
		that.$httpRequest.request({
			that: that,
			url: 'h5/tagClick',
			params: {
				tagId: id,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.topicList[index].clicked = true
					that.showNumber = true
					setTimeout(() => {
						that.showNumber = false
					}, 1000)
					that.page = 1
					// that.list_rows = 10
					// that.list = []
					that.getTodayRecordList()
				} else {
					// that.$toast.msg(res.message, {
					//     icon: 1
					// })
				}

			}
		})


	},
	//保密弹窗
	openTagSecret(id, name) {
		this.clicked_tagId = id
		this.clicked_tagName = name
		this.$refs.confirmPopup.open()

	},
	close() {
		this.$refs.confirmPopup.close()
	},
	//标签设置保密
	tagSecret() {
		let that = this
		that.$refs.confirmPopup.close()
		that.$httpRequest.request({
			that: that,
			url: 'h5/tagSecret',
			params: {
				tagId: that.clicked_tagId,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {

					that.$toast.msg('保密成功', {
						icon: 1
					})
					that.topicList.forEach(item => {
						if (item.id == that.clicked_tagId) {
							item.isSecret = true
						}
					})
				} else {
					that.$toast.msg(res.message, {
						icon: 1
					})
				}

			}
		})
	},
	//标签取消保密
	tagCancelSecret() {
		let that = this
		this.close()
		that.$httpRequest.request({
			that: that,
			url: 'h5/tagCancelSecret',
			params: {
				tagId: that.clicked_tagId,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.$toast.msg('撤销成功', {
						icon: 1
					})
				} else {
					that.$toast.msg(res.message, {
						icon: 1
					})
				}

			}
		})
	},
	//获取所有分类
	getAllCategory() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getAllCategory',
			params: {
				// id:that.id,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.classify = res.data
					that.getAllTag(that.classify[0].id)
					that.current_typeName = that.classify[0].name
					that.currentColor = that.classify[0].colorLight
				}

			}
		})
	},
	//获取指定分类的标签
	getAllTag(id) {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getAllTag',
			params: {
				categoryId: id,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.topicList = res.data

				}

			}
		})
	},

	//个人中心迁移
	selectTime(index) {
		this.timeCurrent = index
		this.pageNo = 1
		this.shadowList = []
		this.getPageList()
	},
	//他的圈子
	tohisCircle(id) {
		uni.navigateTo({
			url: '/pages/my/hisCircle?id=' + id
		})
	},
	//请求好友
	tofriendRequest(id) {
		uni.navigateTo({
			url: '/pages/index/friendRequest?userId=' + id
		})
	},
	//换一换
	changePage() {
		this.getPageList()
	},
	//重置
	reset() {
		this.pageNo = 1
		this.shadowList = []
		this.getPageList()
	},
	//获取我的影子列表
	getPageList() {
		let that = this
		if (that.loading) {
			return false
		}
		that.loading = true
		that.$httpRequest.get({
			that: that,
			url: 'h5/getMyShadowPage',
			params: {
				shadowType: that.timeCurrent,
				pageNo: that.pageNo,
				pageSize: that.pageSize,
			},
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.shadowList = res.data.rows
					// if (that.page === 1) {
					// 	that.shadowList = res.data.rows
					// } else {
					// 	that.shadowList = that.shadowList.concat(res.data.rows)
					// }
					that.pageNo++
				} else {

				}
			}
		})
	},



	getUserInfo() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/info',
			params: {

			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(res.data)
				} else {
					that.upUserInfo({})
				}
			}
		})
	},
	selectEngine(index) {
		this.currentLogo = index
	},
	toSearch() {
		let searchUrl = null;
		console.log(this.currentLogo)
		if (this.currentLogo == 0) {
			searchUrl = `https://www.bing.com/search?q=${encodeURIComponent(this.keyword)}`;

		} else if (this.currentLogo == 1) {
			searchUrl = `https://www.so.com/s?q=${encodeURIComponent(this.keyword)}`;
		} else if (this.currentLogo == 2) {

			searchUrl = `https://www.baidu.com/s?wd=${encodeURIComponent(this.keyword)}`;
		} else {
			searchUrl = `https://www.sogou.com/web?query=${encodeURIComponent(this.keyword)}`;
		}
		window.location.href = searchUrl;
	},
	//获取所有今指数图表数据
	getTotelIndex(id) {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getSiteIndex',
			params: {},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.totelToday = res.data
					// 班组考勤==========================================================================
					this.$refs.tubiao.init(config => {
						config.padding = ['auto', 20, 'auto', 'auto']
						const chart = new F2.Chart(config);
						chart.source(that.totelToday, {
							// value:{//y轴的数值间隔
							// 	tickCount:30
							// }
						});
						chart
							.line()
							.position('date*pointTotal')
							.style('pointTotal', {
								radius: function radius(val) {
									return val > 0 ? [2, 2, 0, 0] : [0, 0, 2, 2];
								},
								lineWidth: 4, // 调整折线宽度
							})
							.adjust('stack'); //不分组
						chart.point().position('date*pointTotal').style({
							stroke: '#5C9FFE', // 边框颜色
							lineWidth: 4, // 边框宽度
							fill: '#ffffff', // 填充颜色，设置为空心需要为白色或透明
							radius: 2 // 点的半径
						});
						chart.axis('date', {
							label: {
								fill: '#666666',
								rotate: -Math.PI / 2,
								textAlign: 'end',
								textBaseline: 'middle',
								fontSize: '15'
							}
						});
						chart.axis('pointTotal', {
							label: {
								fill: '#666666',
								rotate: -Math.PI / 2,
								textAlign: 'end',
								textBaseline: 'middle',
								fontSize: '15'
							}
						});
						chart.legend(false);
						// 柱状图添加文本
						that.totelToday.forEach(function(obj) {
							chart.guide().text({
								position: [obj.date, obj.pointTotal],
								content: obj.pointTotal,
								style: {
									textAlign: 'center',
									textBaseline: 'bottom',
									fontSize: '15',
									fill: 'red',
								},
								offsetY: -10
							});
						});
						chart.render();
						// 需要把 chart 返回
						return chart;
					})
				}

			}
		})
	},
	toLogin() {
		uni.navigateTo({
			url: '/pages/publics/guide'
		})
	}
}